/***global.h
 *	2011.11.4, liyang
 ***/

#ifndef GLOBAL_H_
#define GLOBAL_H_

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <fcntl.h>
#include <stdlib.h>

#define MAXCMD 6									//max cmd/msg number
#define MAXLEN 4096									//the size of the transmission
#define MAXSLEEP 8									//the max sleep time of reconnect
#define SHARENAME "/data/local/myshm" 						//the name of shared memory
#define SHARESIZE 4096								//the size of shared memory
#define DATABASENAME "/data/local/elec.db"			//sqlite3 database
#define SERVERPATHARM "/etc/smartlife/serverconfig"		//serverconfig path on arm
#define SERVERPATHPPC "/mnt/igw_config"				//serverconfig path on ppc
#define SQLITECMDLEN 200							//the max number byte contained in "cmdStr"---command string--sqlite.cpp
#define WAITRES	600									//wait 600*myDelay(5) ms, if no response, return "#ff ff ff ffff#ff#ff ff#ff#"
#define SYNCTIME 10									//sync time

#define DEFALUT_SERVER_IP   "serverip=211.99.30.254\r\n"		//default server ip
#define DEFALUT_SERVER_PORT "serverport=9999\r\n"				//default server port
#define DEFALUT_SER_NUM     "sernum=96322120805181220517\r\n"				//default server port
#define AISAT_CONFIGFILE    "/data/data/cn.com.aisat.android.setting/shared_prefs/cn.com.aisat.android.setting_preferences.xml"
////////////////////////////////////
#include<android/log.h>
#define TAGTEST "guodian"
#define LOGI(FORM,INFO) __android_log_print(ANDROID_LOG_DEBUG,TAGTEST,FORM,INFO)

	#define ERROROUT(ERRSTR) \
			{printf(ERRSTR);\
			if(errno!=0) printf("---%s",strerror(errno));\
			printf("\t file name:%s",__FILE__);\
			LOGI("\t file name:%s",__FILE__);  \
			printf("\t file current line:%d\n",__LINE__);}
	#define PRINTOUT(FORMAT,INFO) \
			{printf(FORMAT,INFO);printf("\n");LOGI(FORMAT,INFO);}

int globalInit();

/***StRecvCmd
*
* save cmd recved from server
***/
struct StRecvCmd
{
	char cmd[MAXLEN];							//recv cmd
	bool flag;									//true:cmd had send to CC; else false
};

/***StSendMsg
*
* save msg need send to server
***/
struct StSendMsg
{
	char msg[MAXLEN];							//send msg
	bool flag;									//true:need send to server; else false
	int retrytimes;								//retrytimes;
};

/***StMemory
*
* shared memory
***/
struct StMemory
{
	int shmFD;									//file descriptor of shared memory
	char *shmADDR;								//started address of shared memory
};

enum{shm_CLEAR,shm_WRITEDNO,shm_WRITED,shm_SWRITED,shm_RESULT,shm_DISPOSE,shm_ALARM,shm_DEVLIST,shm_TIME,shm_CMD,shm_BEALARM,shm_UPGRADE,shm_UPRESPOND,shm_STATUS};//define the flag of shared memory
#endif /* GLOBAL_H_ */
